package bytes;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/11
 */
public class PushbackInputStreamExample {
    public static void main(String[] args) {
        demo();
    }

    private static void demo()
    {
        String source = "12345";
        byte[] b = source.getBytes();
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(b);
        PushbackInputStream push = new PushbackInputStream(byteArrayInputStream);
        int bytes;
        try{
            int size = push.available();
            for(int i=0;i<size;i++){
                bytes = push.read();
                if(i == 1){
                    push.unread(bytes);
                }
                if(i == 3){
                    push.unread(bytes);
                }
                System.out.print((char) bytes);
            }
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
